import styles from './index.module.scss'
import classNames from 'classnames'
import { useState } from 'react'
export const Textarea = ({
  className,
  maxLength = 100,
  value,
  onChange,
  ...rest
}) => {
  const [count, setCount] = useState(value || '')
  const handleChange = (e) => {
    setCount(e.target.value)
    onChange && onChange(e)
  }
  return (
    <div className={styles.root}>
      {/* 文本输入框 */}
      <textarea
        className={classNames('textarea', className)}
        maxLength={maxLength}
        value={count}
        onChange={handleChange}
        {...rest}
      />

      {/* 当前字数/最大允许字数 */}
      <div className="count">
        {count.length}/{maxLength}
      </div>
    </div>
  )
}
